Jes.ext({
	Acluser : {
		init : function(){
			if(!Jes.usSess()) return;
			Jes.cBtn('welcome.html');
			Jes('search').onclick=function(){Jes.Acluser.query();}
			Jes('exp').onclick=function(){Jes.exp('acluser_query_sql@acl');}
			Jes('add').onclick=function(){Jes.Acluser.open('op');}
			Jes('del').onclick=function(){Jes.Acluser.del();}
			initTabs('tabView_1',Array('用户管理'),0,'100%',90,Array(false));
			this.query();
		}
		,query : function(){
			Jes.page('acluser_query_sql@acl');
		}
		,open : function(type,id){
			var args= arguments;
			switch(type){
				case 'op':
						_newTab(id?'用户编辑':'用户新增','acluserop.html'.J({id:id}));
					break;
			}
		}
		//ajax
		,check : function(val){
			var msg=true;
			Jes.sync(function(){
				//不能使用Jes.vals取值 需要传入par
				Jes.queryO('checkuser_query_sql@acl',{lo:0,par:{loginid:val,id:Jes.v('id')}},function(da){
					if(da!=null) msg = '已经存在。';
				});
			});
			return msg;
		}
		,selOrg : function(){
			var pos=Jes.pos(Jes('flydiv1'));
			Jes.FlyDiv.show('mdiv',null,null,pos.x-250,pos.y+20);
		}
		,del : function(){
			var ids = Jes.val('id');
			if(Jes.isN(ids)){alert('至少选择一项!');return;}
			if(!confirm('你确定删除账号吗？')) return;
			Jes.sql('acluser_del_sql@ms',{ids:ids});
		}
		,delPf : function(id){
			if(!confirm('你确定删除评分项吗？')) return;
			Jes.sql('mspf_delete_hql@hr',{ids:id},function(){
				alert('删除成功!');
				Jes.Mspf.queryByMb();
			});
		}
		,opInit : function(){
			if(!Jes.usSess()) return;
			Jes.cBtn();
			Jes('add').onclick=function(){Jes.Acluser.save();}
			var req=Jes.req();
			Jes.vals(req);
			if(req.id){
				Jes.queryO('Acluser',{par:{id:req.id}});
			}else{
				if(req.oid) Jes.hide('flydiv1');
			}
			Jes.orgTree.init();
			this.roleTree.init();
		}
		,roleTree :{
			init : function(){
				Jes.rpc('getRoleTree@acl',{par:{drag:'0',all:'1',sync:'1',type:'chk'}},function(da){
					Jes.html('role_tree',da);
					treeObj = new JSDragDropTree();
					//treeObj.fn = 'Jes.Fmenu.edit';
					treeObj.setTreeId('dhtml_tree');
					treeObj.setMaximumDepth(10);
					/*
					treeObj.setAddAllowed(true);
					treeObj.setEditAllowed(true);
					treeObj.setDeleteAllowed(true);
					treeObj.setUserFunctionAfterDropDragableNodes(function(id,pId){Jes.Fmenu.moveNode(id,pId)});
					*/
					treeObj.setMessageMaximumDepthReached('超过最多级别'); // If you want to show a message when maximum depth is reached, i.e. on drop.
					treeObj.initTree();
					treeObj.expandAll();
					//treeObj.expand(true);
					Jes.Acluser.roleTree.queryRoleByUs();
				});
			}
			,queryRoleByUs : function(){
				Jes.query('roleidbyusid_query_sql@acl',function(da){
					var rids= Jes.names('tree.roleid');
					Jes.each(rids,function(i){//优化
						Jes.each(da,function(j){
							if(rids[i].value==da[j].id){
								rids[i].checked=true;
								return false;
							} 
						});
					});
				});
			}
		}
		,save : function(){
			var sql=Jes.req('oid')?'acluserbyorg_query_sql@acl':(Jes.req('rid')?'acluserbyrole_query_sql@acl':'acluser_query_sql@acl');
			Jes.save('Acluser@acl',{},sql);
		}
	}
	,AcluserQuery : {
		init : function(){
			if(!Jes.usSess()) return;
			Jes.cBtn('welcome.html');
			Jes('search').onclick=function(){Jes.AcluserQuery.query();}
			Jes('add').onclick=function(){Jes.AcluserQuery.addUs();}
			//initTabs('tabView_1',Array('用户管理'),0,'100%',90,Array(false));
			Jes.vals(Jes.req());
			this.query();
		}
		,query : function(){
			Jes.page('aclroleuser_query_sql@acl');
		}
		,addUs : function(){
			var ids = Jes.val('id');
			if(Jes.isN(ids)){alert('至少选择一项!');return;}
			if(!confirm('你确定关联用户吗？')) return;
			Jes.rpc('relaRoleuser@acl',{par:{usids:ids,rid:Jes.v('rid')}},function(da){
				alert(da);
				Jes.page('aclroleuser_query_sql@acl',{lo:0});
				var _o = Jes.opener(),__o = _o.frames['jes_'+top.tabId];
				_o.Jes.Aclrole.queryUs();
				//Jes.close();
			});
		}
	}
	,Pwd : {
		init : function(){
			if(!Jes.usSess()) return;
			Jes.cBtn('welcome.html');
			Jes('add').onclick=function(){Jes.Pwd.save();}
			initTabs('tabView_1',Array('修改密码'),0,'100%',90,Array(false));
		}
		,save : function(){
			Jes.save('modifyPwd@acl',function(da){
				alert("修改密码成功!");
			});
		}
	}
	,User : {
		init : function(){
			if(!Jes.usSess()) return;
			Jes.cBtn('welcome.html');
			Jes('add').onclick=function(){Jes.User.save();}
			initTabs('tabView_1',Array('个人信息修改'),0,'100%',90,Array(false));
			Jes.vals(usINFO);
			Jes.vals({'email':usINFO.uemail,'rk':usINFO.urk});
			Jes.orgTree.init();
		}
		,save : function(){
			Jes.save('modifyUser@acl',function(da){
				alert("个人信息修改成功!");
			});
		}
	}
});